home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / C / MakeIndex < prev    next >
Text File  |  1998-06-27  |  6KB  |  185 lines

  1. /* MakeIndex
  2.     Hacked by Andy Macklin to produce a sort of index of doc/guide files.
  3.     My version of grep uses the following syntax...
  4.     usage: grep [-[[AB] ]<num>] [-[CEFGVchilnqsvwx]] [-[ef]] <expr> [<files...>]
  5.  
  6.         Requirements:   grep
  7.                         sort
  8.                         copy
  9.                         searchguide (optional)
  10.                         same syntax as buildindex  (optional)
  11.  
  12. */
  13.  
  14. buildidx='Y' /*Change to 'Y' for an all in one script ;) */
  15. SGUIDE='N'   /*Change to 'Y' for an automatic search button in the docs guide file */
  16.  
  17. address command
  18.  
  19. Volume = left(pragma('D'),pos(':',pragma('D')))
  20.  
  21. /* Clear icon position */
  22. /* 'nopos' Volume'disk nodd' */
  23. /* Delete trashcan */
  24. 'delete >NIL: 'Volume'Trashcan all force'
  25.  
  26. /* defines and such */
  27.         /* GREP CALL */
  28. GREPCALL = "grep"
  29.         /* GREP HELP CALL */
  30. GREPHELP = "grep -h"
  31.         /* Where's the CUCD index? */
  32. IDXLOC = Volume'CDsupport/CUCD.index'
  33.         /* Where's the finished guide to go to?*/
  34. outfile = Volume'CDsupport/Docs.guide'
  35.         /* Path to MultiView */
  36. MView = Volume'Utilities/MultiView'
  37.         /* Extensions to search for */
  38. Extensions = 'guide|doc|dok|txt|text|asc|man|readme'
  39.  
  40. if buildidx='Y' then do
  41.     /* NB the column format is important for the sort fuction later */
  42.     'delete >NIL:' outfile    /* Otherwise the guide will contain a reference to itself */
  43.     'list' Volume'~(C|CDSupport|Classes|CUCD|Devs|Expansion|Fonts|L|Libs|Locale|Prefs|Rexxc|S|Storage|System|Tools|Utilities) all files pat=~(#?.info) lformat "%-33N%P%N" to' IDXLOC
  44.     'list' Volume'CUCD/(Kids|CDROM|Demos|Games|Graphics|Information|Magazine|Online|Previews|Programming|Readers|Sound|Utilities) all files pat=~(#?.info) lformat "%-33N%P%N" to' IDXLOC
  45.     end
  46.  
  47. grepfile = "t:grepoutput." || Pragma("i")
  48. agfile = "t:grepguide." || Pragma("i")
  49. CR      = d2c(10)
  50. TAB     = d2c(9)
  51.  
  52. /* setup the output file - we need this first so we can show errors in it */
  53. IF Open(agfp,agfile,'w') = 0 THEN DO
  54.         SAY "Couldn't create amigaguide file ("||agfile||")"
  55.         EXIT 20
  56.         END
  57.  
  58. call writeln(agfp,'@DATABASE "CD docs"')
  59. call writeln(agfp,'@REMARK created by Andys MakeIndex v2 :)')
  60. call writeln(agfp,'')
  61. call writeln(agfp,'@NODE Main "DOCS & GUIDES"')
  62. call writeln(agfp,'')
  63.  
  64. /* Put a search button (needs searchguide in the CDs path) */
  65. if SGUIDE='Y' then do
  66. call writeln(agfp,'@{" Search " SYSTEM "RUN SearchGuide '||substr(outfile,pos(':',outfile)+1)||'" }')
  67. call writeln(agfp,'')
  68. end
  69.  
  70. SIGNAL ON FAILURE
  71. ADDRESS COMMAND
  72. 'delete >NIL:' grepfile
  73. do until Extensions = ''
  74.     parse var Extensions ext '|' Extensions
  75.     GREPCALL '-F .'ext IDXLOC '>>' grepfile
  76.     end
  77. 'rename' grepfile ' to ' grepfile||'.old'
  78. 'sort' grepfile||'.old' grepfile 'colstart 37'
  79. SIGNAL OFF FAILURE
  80.  
  81. IF Open(grepfp,grepfile,'r') = 0 THEN DO
  82.         CALL HandleError("Couldn't open grep output file ("||grepfile||")","")
  83.         END
  84.  
  85. /*************************************************************************
  86. **  Format of Grep output
  87. **  =====================
  88. **
  89. **HTMLit!.guide                 CUCD4:Magazine/WiredWorld/HTMLit!/HTMLit!.guide
  90. **DemosOfTheWorld.guide         CUCD4:CUCD/Demos/DemosOfTheWorld/DemosOfTheWorld.guide
  91. **mc12.guide                    CUCD4:CUCD/Demos/Malevolent_Creations/mc12.guide
  92. **iml-Feb71.guide               CUCD4:CUCD/Graphics/Imagine/iml-Feb71.guide
  93. **Dust.guide                    CUCD4:CUCD/Graphics/Imagine/Dust/Docs/Dust.guide
  94. **DustEnglish.guide             CUCD4:CUCD/Graphics/Imagine/Dust/Docs/DustEnglish.guide
  95. **IM_Organizer.guide            CUCD4:CUCD/Graphics/Imagine/IM_Organiser/IM_Organizer.guide
  96. **TextureStudio.guide           CUCD4:CUCD/Graphics/Imagine/TextureStudio/Docs/TextureStudio.guide
  97. **ncFTPevents.guide             CUCD4:CUCD/Online/ThorStuff/Programs/ncFTPevents/Thor/docs/ncFTPevents.guide
  98. **
  99. ****************************************************************************/
  100.  
  101. line = ReadLn(grepfp)
  102. IF EOF(grepfp) THEN DO
  103.         call close(grepfp)
  104.         say 'No files found'
  105.         exit 10
  106.         END
  107.  
  108.  
  109.         CALL Pragma('W','n')            /* turn off dos requesters */
  110.  
  111. DO WHILE ~EOF(grepfp)
  112.         /* START BY LOOKING FOR FILENAMES */
  113.         currentfile = Strip(Left(line,Length(Word(line,1))),"B")
  114.         location = strip(right(line,length(line)-length(word(line,1))),"B")
  115.         if right(currentfile,5) ='guide' then
  116.         do
  117.             node='/main'
  118.             action='link "'
  119.         end
  120.         else
  121.         do
  122.             node=''
  123.             action='system "'MView' '
  124.         end
  125.         endif
  126.         call writeln(agfp,'@{" 'currentfile left('',33-length(currentfile))' "' action||location||node'" }   'substr(location,pos(':',location)+1))
  127.         line = ReadLn(grepfp)
  128.                 END
  129.  
  130. call WriteLn(agfp,'@ENDNODE')
  131.  
  132. call Close(grepfp)
  133. call Close(agfp)
  134.  
  135.        CALL Pragma('W','w')            /* turn dos requesters back on */
  136.  
  137. address command
  138. 'copy' agfile outfile
  139. 'delete >NIL:' grepfile
  140. 'delete >NIL:' grepfile||'.old'
  141. 'delete >NIL:' agfile
  142.  
  143. EXIT
  144.  
  145. FAILURE:
  146. ERROR:
  147.         errRC = RC
  148.         CALL Close(grepfp)
  149.         CALL HandleError("Grep Failure:"|| CR || "    " || FullCommand ,grepfile)
  150.         EXIT
  151.  
  152. /***************************************************/
  153. HandleError: PROCEDURE EXPOSE agfp grepfile agfile grephelp
  154.  
  155.         ErrorText = arg(1)
  156.         ErrorFile = arg(2)
  157.  
  158.         call writeln(agfp,'-=-=-=-=-=-=-=-=-=  E R R O R  =-=-=-=-=-=-=-=-=-')
  159.         call writeln(agfp,ErrorText)
  160.         call writeln(agfp,' ')
  161.  
  162.         IF (ErrorFile~="" & Exists(ErrorFile)) THEN DO
  163.                 call writeln(agfp,"Response:")
  164.                 ADDRESS COMMAND GREPHELP '>>'ErrorFile
  165.                 Open('errorfp',ErrorFile,'r')
  166.                 DO WHILE ~EOF('errorfp')
  167.                         call writeln(agfp,"    " || ReadLn('errorfp'))
  168.                         END
  169.                 call close('errorfp')
  170.                 END
  171.  
  172.         call writeln(agfp,"")
  173.         call writeln(agfp,"Current Path:")
  174.         call writeln(agfp,"    "||Pragma("D"))
  175.         call writeln(agfp,'@ENDNODE')
  176.  
  177.         call close(agfp)
  178.  
  179.         IF Exists(grepfile) THEN Delete(grepfile)
  180.         Delete(agfile)
  181.  
  182.         EXIT 20
  183. RETURN
  184.  
  185.